
#ifndef MODBUS_H
#define MODBUS_H

#ifdef __cplusplus
extern "C" {
}
#endif

#include <stdint.h>
// #define MODBUS_FC_READ_COILS               0x01
// #define MODBUS_FC_READ_DISCRETE_INPUTS     0x02
// #define MODBUS_FC_READ_HOLDING_REGISTERS   0x03
// #define MODBUS_FC_READ_INPUT_REGISTERS     0x04
// #define MODBUS_FC_WRITE_SINGLE_COIL        0x05
// #define MODBUS_FC_WRITE_SINGLE_REGISTER    0x06
// #define MODBUS_FC_READ_EXCEPTION_STATUS    0x07
// #define MODBUS_FC_WRITE_MULTIPLE_COILS     0x0F
// #define MODBUS_FC_WRITE_MULTIPLE_REGISTERS 0x10
// #define MODBUS_FC_REPORT_SLAVE_ID          0x11
// #define MODBUS_FC_MASK_WRITE_REGISTER      0x16
// #define MODBUS_FC_WRITE_AND_READ_REGISTERS 0x17

typedef  enum {
    MB_FC_01_RD_COILS = 0x01,
    MB_FC_02_RD_DIS_INPUTS = 0x02,
    MB_FC_03_RD_HOLDING_REGS,
    MB_FC_04_RD_INPUT_REGS,
    MB_FC_05_WT_S_COIL,
    MB_FC_06_WT_S_REG,
    MB_FC_07_RD_EX_STATUS,
    MB_FC_0F_WT_MUL_COILS =0x0F,
    MB_FC_10_WT_MUL_REGS =0x10,
    MB_FC_11_RP_SLAVE_ID =0x11,
} mb_fc_t;

typedef struct {
    int dev_id;
    uint16_t bsp;
    uint8_t stopbit;
    uint8_t databit;
    uint8_t evet;
} mb_dev_t;


typedef struct {
    uint8_t tbuf[256];
    uint8_t rbuf[256];
    uint8_t tx_len;
    uint8_t *rx_len;
} mb_adu_t;


typedef struct {
    mb_fc_t mb_fc;
    int (*transmit)(mb_dev_t *dev, mb_adu_t *mb_adu);
} mb_transmit_t;


#endif
